# base build image
FROM registry.cn-shenzhen.aliyuncs.com/infrastlabs/golang:1.13.9-alpine3.10 as gomod
  ARG dir=/go/src/gitee.com/infraslabs/k8s-kubeedge-sample
  # use go modules
  ENV GO111MODULE=on
  ENV GOPROXY=https://goproxy.cn
  # only copy go.mod and go.sum
  WORKDIR ${dir}
  COPY go.mod .
  #COPY go.sum .
  RUN go mod download

FROM gomod AS builder
  ARG dir=/go/src/gitee.com/infraslabs/k8s-kubeedge-sample
  # use go modules
  ENV GO111MODULE=on
  ENV GOPROXY=https://goproxy.cn
  # Copy in the go src
  WORKDIR ${dir}
  COPY . .
  RUN pwd; ls -lh; \
    # cd golang_http_message; \
    sh go-build.sh; ls -lh; 

FROM registry.cn-shenzhen.aliyuncs.com/infrasync/alpine:3.13.12
ARG dir=/go/src/gitee.com/infraslabs/k8s-kubeedge-sample
WORKDIR /app
# COPY ./http-message /app/http-message
COPY --from=builder ${dir}/http-message /app/http-message
EXPOSE 17080
# CMD ["sh", "-c", "while true; do echo hello-sam.; sleep 1.002; done"]
# echo exec:http-message; #with inital log
CMD ["sh", "-c", "echo exec:http-message; exec /app/http-message"]
